package cn.witsky.rtp2ws.config;

import java.util.List;
import java.util.Map;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

@Configuration
@ConfigurationProperties(prefix = "list")
public class AppConfig {
	private volatile Map<String, String> map = null;
	
	private List<App> apps = Lists.newArrayList();	
	
	
	public List<App> getApps() {
		return apps;
	}

	public void setApps(List<App> apps) {
		this.apps = apps;
	}
	public String getSecretKey(String appKey) {
		if(map==null) {
			synchronized (this) {
				if(map==null) {
					map=Maps.newHashMap();
					for(App app:apps) {
						map.put(app.getAppKey(),app.getSecretKey());
					}
				}
			}
		}
		return map.get(appKey);
	}


	public static class App{
		private String appKey;
		private String secretKey;
	
		public String getAppKey() {
			return appKey;
		}
		public void setAppKey(String appKey) {
			this.appKey = appKey;
		}
		public String getSecretKey() {
			return secretKey;
		}
		public void setSecretKey(String secretKey) {
			this.secretKey = secretKey;
		}
		
		
	}
}
